import requests

from src.core.lol.luc.ws import WsLolClient
from .client import LCUClient
from .commands import *

"""
lol客户端类,使用LCU接口
"""
class lol:
    def __init__(self):
        self.client = None
        self.ws_client = None
        self.current_user = None

    def init_client(self):
        self.client = LCUClient()
        self.ws_client = WsLolClient()
        return self.client.is_valid() and self.ws_client.is_valid()

    def get_current_user(self):
        base_url = self.client.get_base_url()
        if(base_url):
            url = self.client.base_url + GET_CURRENT_USER
            resp = requests.get(url, verify=False)
            if resp.status_code == 200:
                print(resp.json())
                self.current_user = resp.json()
                return self.current_user
        return None

    def get_games_by_puuid(self):
        base_url = self.client.get_base_url()
        if(base_url):
            url = self.client.base_url + "/lol-match-history/v1/products/lol/{}/matches?begIndex=0&endIndex=10"
            resp = requests.get(url.format(self.current_user['puuid']), verify=False)
            print(resp.json())
            if resp.status_code == 200:
                print(resp.json())
                return resp.json()